package com.zero.rocketmq.api.broadcast;

import com.zero.rocketmq.api.utils.RocketMQContents;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class BroadcastProducer {

    public static void main(String[] args) throws MQClientException {

        DefaultMQProducer producer = new DefaultMQProducer(RocketMQContents.PRODUCER_GROUP);

        producer.setNamesrvAddr(RocketMQContents.NAMESERVER_ADDR);

        producer.start();

        try{
            for (int i = 0;i< 10;i++){

                Message msg = new Message(RocketMQContents.TOPIC,
                        "TagA",
                        ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET)
                );

                SendResult sendResult = producer.send(msg);
                System.out.printf("%s%n", sendResult);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        producer.shutdown();

    }
}
